package com.mt.restaurant.entity.material;

import javax.persistence.*;
import java.io.Serializable;
import com.mt.common.core.annotation.DColumn;
import com.mt.common.core.annotation.DEntity;
import com.mt.common.core.web.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;



import com.mt.restaurant.entity.material.Material;

@DEntity(label="库存记录",comment="",moduleLabel="原材料管理")
@Entity(name="restaurant_stock_record")
@Table(name = "restaurant_stock_record" , indexes = { @Index(name = "index_material_id", columnList = "material_id")  })
@ApiModel(description = "库存记录:")
public class StockRecord extends BaseEntity implements Serializable{
	private static final long serialVersionUID = 1L;

	@DColumn(index=3,label="材料id",foreignEntity="Material",comment="供应原材料",component="对象选择",where=false)
	@ApiModelProperty(value = "材料id:供应原材料")
	@Column(name="material_id",length=255,nullable=true,unique=false)
	private Long materialId;

	@Transient
	private Material material;

	@Transient
	@ApiModelProperty(value = "材料id名称:供应原材料")
	@DColumn(index=3,label="材料id",foreignEntity="Material",comment="供应原材料")
	private String materialName;

	@DColumn(index=4,label="数量",comment="",component="数字，小数",where=false)
	@ApiModelProperty(value = "数量:")
	@Column(name="quantity",length=255,nullable=true,unique=false)
	private Double quantity;

	@DColumn(index=5,label="操作",comment="入库、退库、领用、调拨等操作",component="文本",where=false)
	@ApiModelProperty(value = "操作:入库、退库、领用、调拨等操作")
	@Column(name="operation",length=255,nullable=false,unique=false)
	private String operation;

	@DColumn(index=6,label="入库仓库id",comment="",component="数字，整数",where=false)
	@ApiModelProperty(value = "入库仓库id:")
	@Column(name="in_store_id",length=255,nullable=true,unique=false)
	private Long inStoreId;

	public Long getMaterialId() {
		return this.materialId;
	}

	public void setMaterialId(Long materialId) {
		this.materialId = materialId;
	}

	public Double getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Double quantity) {
		this.quantity = quantity;
	}

	public String getOperation() {
		return this.operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	public Long getInStoreId() {
		return this.inStoreId;
	}

	public void setInStoreId(Long inStoreId) {
		this.inStoreId = inStoreId;
	}


	public Material getMaterial() {
		return this.material;
	}

	public void setMaterial(Material material) {
		if(material == null){
		}
		else
		{
		this.materialId = material.getEid();
		this.material = material;		
		}
}
	public void newStockRecordByStoreMaterial(Integer operation,Double quantity,StoreMaterial storeMaterial) {
		if (operation==0){
			this.operation = "退库";
		}else if(operation==1){
			this.operation = "入库";
		}else if(operation==2){
			this.operation = "领用";
		}else if(operation==3){
			this.operation = "损耗";
		}
		this.quantity = quantity;
		this.materialId = storeMaterial.getMaterialId();
		this.name = storeMaterial.getName();
		this.inStoreId = (long)1;
	}

	public String getMaterialName() {
		return this.materialName;
	}

	public void setMaterialName(String materialName) {
		this.materialName = materialName;
	}



}
